package com.psp.bu.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.northend.util.NumUtil;
import com.psp.bu.controller.res.ListResult;
import com.psp.bu.controller.res.bean.RMsgListBean;
import com.psp.bu.controller.res.bean.ROrderMsgListBean;
import com.psp.bu.controller.res.bean.RSysMsgListBean;
import com.psp.bu.controller.springmvc.req.GetMsgAllParam;
import com.psp.bu.controller.springmvc.req.GetOrderMsgListParam;
import com.psp.bu.controller.springmvc.req.GetSysMsgListParam;
import com.psp.bu.service.MsgService;
import com.psp.bu.service.impl.PageResult;

@Component
public class MessageController {

	@Autowired
	MsgService msgServiceImpl;

	/**
	 * 获取全部消息
	 * 
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ListResult<RMsgListBean> getAll(GetMsgAllParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ListResult<RMsgListBean> result = new ListResult<>();
		int page = NumUtil.toInt(param.getPage(), 0);
		int pageSize = 10;
		String uid = "";
		PageResult<RMsgListBean> resList = msgServiceImpl.getAll(page, pageSize, uid);

		result.setToken(param.getToken());
		result.setData(resList.getData());
		result.setTotalSize(resList.getCount());
		result.setPage(page);
		return result;
	}

	/**
	 * 订单消息
	 * 
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ListResult<ROrderMsgListBean> orderMsgs(GetOrderMsgListParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ListResult<ROrderMsgListBean> result = new ListResult<>();
		int page = NumUtil.toInt(param.getPage(), 0);
		int pageSize = 10;
		String uid = "";
		PageResult<ROrderMsgListBean> resList = msgServiceImpl.getOrderMsgs(page, pageSize, uid);

		result.setToken(param.getToken());
		result.setData(resList.getData());
		result.setTotalSize(resList.getCount());
		result.setPage(page);
		return result;
	}

	/**
	 * 系统消息
	 * 
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ListResult<RSysMsgListBean> sysMsgs(GetSysMsgListParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ListResult<RSysMsgListBean> result = new ListResult<>();
		int page = NumUtil.toInt(param.getPage(), 0);
		int pageSize = 10;
		String uid = "";
		PageResult<RSysMsgListBean> resList = msgServiceImpl.getSysMsgs(page, pageSize, uid);

		result.setToken(param.getToken());
		result.setData(resList.getData());
		result.setTotalSize(resList.getCount());
		result.setPage(page);
		return result;
	}

}
